<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <%@include file="/WEB-INF/views/common/header.jsp" %>
</head>
<body>
<%@include file="/WEB-INF/views/common/top.jsp" %>
<%@include file="/WEB-INF/views/common/nav.jsp" %>

<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <div class="show-top-grids">
        <div class="main-grids about-main-grids">
            <h4>兼职信息列表</h4>
            <div class="recommended-info">
                <hr class="layui-bg-green">
                <form class="form-inline" class="layui-form layui-form-pane" method="post"
                      action='<c:url value="/part/list"/>'>
                    <div class="row bs-example">

                        <%--<div class="form-group col-md-2">--%>
                        <%--<input type="text" id="title" name="title" placeholder="输入标题" autocomplete="off"--%>
                        <%--value="${response.query.title}" class="layui-input">--%>
                        <%--</div>--%>


                    </div>


                    <div class="row bs-example" style="margin-top: 1em;">
                        <div class="form-group col-md-2">
                            <button class="layui-btn" id="query" type="submit">查询</button>
                        </div>
                    </div>


                    <div class="about-grids" style="margin-top: 2em;">
                        <table class="layui-table">
                            <thead>
                            <tr>
                                <th style="width:15%;">标题</th>
                                <th style="width:8%">薪资(天)</th>
                                <th style="width:8%">人数(天)</th>
                                <th style="width:9%">开始日期</th>
                                <th style="width:9%">结束日期</th>
                                <th style="width:8%">状态</th>
                                <th style="width:10%">公司名称</th>
                                <th style="width:10%">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:forEach items="${response.data}" var="part" varStatus="status">
                                <tr>
                                    <td>${part.title}</td>
                                    <td>${part.salary}元/人/天</td>
                                    <td>${part.peopleNumber}人</td>
                                    <td>${part.startTimeStr}</td>
                                    <td>${part.endTimeStr}</td>
                                    <td>
                                        <c:if test='${part.status.code == 1}'>初始化</c:if>
                                        <c:if test='${part.status.code == 2}'>未开始</c:if>
                                        <c:if test='${part.status.code == 3}'>进行中</c:if>
                                        <c:if test='${part.status.code == 4}'>活动结束</c:if>
                                        <c:if test='${part.status.code == 5}'>薪资结算中</c:if>
                                        <c:if test='${part.status.code == 6}'>完成</c:if>
                                    </td>
                                    <td>${part.companyName}</td>
                                    <td>
                                        <div class="layui-table-cell laytable-cell-1-9">
                                            <c:if test='${part.status.code < 3}'>
                                                <a onclick="edit(${part.id})"
                                                   class="href-a layui-btn layui-btn-small">编辑</a>
                                            </c:if>
                                            <a onclick="edit(${part.id})"
                                               class="href-a layui-btn layui-btn-small">分配人员</a>
                                            <a onclick="deleteUser(${part.id});"
                                               class="href-a layui-btn layui-btn-small">查看详情</a>
                                            <c:if test='${part.status.code < 3}'>
                                                <a onclick="delete(${part.id})"
                                                   class="layui-btn layui-btn-danger layui-btn-small">删除</a>
                                            </c:if>
                                        </div>
                                    </td>
                                </tr>
                            </c:forEach>
                            </tbody>
                        </table>
                    </div>

                    <div>
                        <jsp:include page="/WEB-INF/views/common/pagination.jsp"/>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

</body>

<script type="application/javascript">
    layui.use(['layer', 'laydate'], function () {
        window.layer = layui.layer;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#startTime'
        });
        laydate.render({
            elem: '#endTime'
        });
    });

    /*导航栏参数*/
    var $nav_a = $("#ul_nav a[href='/part/list']");
    $nav_a.parent().addClass("active");
    $nav_a.parent().parent().css("display", "block");


    /*创建用户*/
    function createUser() {
        window.open('<c:url value="/user/create"/>');
    }
    /*编辑兼职信息*/
    function edit(id) {
        window.open('<c:url value="/part/edit"/>?partId=' + id + '');
    }

    /**
     * 删除用户
     * @param id
     */
    function deleteUser(id) {
        window.layer.confirm('确定删除用户？', {btn: ['删除', '取消']}, function () {
            $.ajax({
                url: '<c:url value="/user/delete"/>',
                dataType: 'json',
                type: 'post',
                data: {userId: id},
                success: function (data) {
                    if (data.code !== "200") {
                        window.layer.msg(data.message, {icon: 5, anim: 6});
                    } else {
                        $("#query").click();
                    }
                }, error: function () {

                }
            });
        }, function () {
        });
    }

</script>


</html>
